package com.xbongbong.paas.elasticsearch.constant;

/**
 * 创建时间： 2018/10/12 11:07
 * 修改时间： 2018/10/12 11:07 梁鲁江
 *
 * @author 梁鲁江
 */
public class EsMappingConstant {
    /**
     * 索引的settings (注意最外层要以index开头，而不是以完整的settings包裹，最外层由框架提供，否则会报错)
     */
    public static final String ELASTIC_SETTINGS_ROOT = "{\"index\":{\"mapping\":{\"total_fields\":{\"limit\":\"1000\"}},\"max_ngram_diff\":20,\"number_of_shards\":\"5\",\"number_of_replicas\":\"1\",\"analysis\":{\"analyzer\":{\"chinese_text\":{\"filter\":[\"chinese_text\"],\"tokenizer\":\"keyword\"},\"email_url_analyzer\":{\"filter\":[\"trim\"],\"tokenizer\":\"uax_url_email\",\"type\":\"custom\"},\"index_email_analyzer\":{\"filter\":[\"lowercase\",\"name_ngram_filter\",\"trim\"],\"tokenizer\":\"standard\",\"type\":\"custom\"},\"index_phone_analyzer\":{\"char_filter\":[\"digit_only\"],\"filter\":[\"trim\"],\"tokenizer\":\"digit_edge_ngram_tokenizer\",\"type\":\"custom\"},\"search_email_analyzer\":{\"filter\":[\"lowercase\",\"trim\"],\"tokenizer\":\"standard\",\"type\":\"custom\"},\"search_phone_analyzer\":{\"char_filter\":[\"digit_only\"],\"filter\":[\"trim\"],\"tokenizer\":\"keyword\",\"type\":\"custom\"},\"pinyin_analyzer\":{\"tokenizer\":\"my_pinyin\"}},\"char_filter\":{\"digit_only\":{\"pattern\":\"\\\\D+\",\"replacement\":\"\",\"type\":\"pattern_replace\"}},\"filter\":{\"chinese_text\":{\"country\":\"CN\",\"language\":\"cn\",\"type\":\"icu_collation\"},\"name_ngram_filter\":{\"max_gram\":\"20\",\"min_gram\":\"1\",\"type\":\"ngram\"}},\"tokenizer\":{\"digit_edge_ngram_tokenizer\":{\"max_gram\":\"15\",\"min_gram\":\"1\",\"token_chars\":[\"digit\"],\"type\":\"edge_ngram\"},\"my_pinyin\":{\"type\":\"pinyin\",\"keep_first_letter\":true,\"keep_separate_first_letter\":false,\"keep_full_pinyin\":false,\"limit_first_letter_length\":20,\"lowercase\":true,\"keep_none_chinese\":false}}}}}";
    /**
     * 统计字段的setting,放宽字段限制到3000
     */
    public static final String ELASTIC_STATISTIC_SETTINGS_ROOT = "{\"index\":{\"mapping\":{\"total_fields\":{\"limit\":\"3000\"}},\"max_ngram_diff\":20,\"number_of_shards\":\"6\",\"number_of_replicas\":\"1\",\"analysis\":{\"analyzer\":{\"chinese_text\":{\"filter\":[\"chinese_text\"],\"tokenizer\":\"keyword\"},\"email_url_analyzer\":{\"filter\":[\"trim\"],\"tokenizer\":\"uax_url_email\",\"type\":\"custom\"},\"index_email_analyzer\":{\"filter\":[\"lowercase\",\"name_ngram_filter\",\"trim\"],\"tokenizer\":\"standard\",\"type\":\"custom\"},\"index_phone_analyzer\":{\"char_filter\":[\"digit_only\"],\"filter\":[\"trim\"],\"tokenizer\":\"digit_edge_ngram_tokenizer\",\"type\":\"custom\"},\"search_email_analyzer\":{\"filter\":[\"lowercase\",\"trim\"],\"tokenizer\":\"standard\",\"type\":\"custom\"},\"search_phone_analyzer\":{\"char_filter\":[\"digit_only\"],\"filter\":[\"trim\"],\"tokenizer\":\"keyword\",\"type\":\"custom\"},\"pinyin_analyzer\":{\"tokenizer\":\"my_pinyin\"}},\"char_filter\":{\"digit_only\":{\"pattern\":\"\\\\D+\",\"replacement\":\"\",\"type\":\"pattern_replace\"}},\"filter\":{\"chinese_text\":{\"country\":\"CN\",\"language\":\"cn\",\"type\":\"icu_collation\"},\"name_ngram_filter\":{\"max_gram\":\"20\",\"min_gram\":\"1\",\"type\":\"ngram\"}},\"tokenizer\":{\"digit_edge_ngram_tokenizer\":{\"max_gram\":\"15\",\"min_gram\":\"1\",\"token_chars\":[\"digit\"],\"type\":\"edge_ngram\"},\"my_pinyin\":{\"type\":\"pinyin\",\"keep_first_letter\":true,\"keep_separate_first_letter\":false,\"keep_full_pinyin\":false,\"limit_first_letter_length\":20,\"lowercase\":true,\"keep_none_chinese\":false}}}}}";

    /**---------------------------------------------------------------mapping-----------------------------------------------------*/
    public static final String ELASTIC_MAPPING_ROOT = "{\"properties\":{}}";
    /**
     * 中文类型   外部用于查询， raw 用于排序（raw的分词采用拼音分词）  keyword用于精确匹配   添加纯数字型的搜索
     */
    public static final String MAPPING_FOR_STRING_SORT = "{\"type\":\"text\",\"index\":true,\"analyzer\":\"index_email_analyzer\",\"search_analyzer\":\"search_email_analyzer\",\"fields\":{\"raw\":{\"type\":\"text\",\"analyzer\":\"pinyin_analyzer\",\"fielddata\":true},\"keyword\":{\"type\":\"keyword\",\"ignore_above\":256}}}";
    /**
     * text
     */
    public static  final String MAPPING_FOR_TEXT = "{\"type\":\"text\",\"fields\":{\"keyword\":{\"type\":\"keyword\",\"ignore_above\":256}}}";
    /**
     * 知识库text，索引前一千个字段，扩展问法也需要一千个字
     */
    public static  final String KNOWLEDGE_MAPPING_FOR_TEXT = "{\"type\":\"text\",\"fields\":{\"keyword\":{\"type\":\"keyword\",\"ignore_above\":1000}}}";


    /**
     * phone 或email 类型的分词
     */
    public static final String MAPPING_FOR_PHONE_OR_EMAIL = "{\"type\":\"text\",\"analyzer\":\"index_email_analyzer\",\"search_analyzer\":\"search_email_analyzer\"}";
    /**
     * phone 的分词，加了raw排序
     */
    public static final String MAPPING_FOR_PHONE = "{\"analyzer\":\"index_email_analyzer\",\"fields\":{\"raw\":{\"type\":\"text\",\"fielddata\":true}},\"search_analyzer\":\"search_email_analyzer\",\"type\":\"text\"}";
    /**
     * nested 类型 （用于团队等）
     */
    public static final String MAPPING_FOR_NESTED = "{\"type\":\"nested\"}";
    /**
     * 定位(地址+经纬度)
     */
//    public static final String MAPPING_FOR_LOCATION = "{\"properties\":{\"address\":{\"fields\":{\"keyword\":{\"ignore_above\":256,\"type\":\"keyword\"}},\"type\":\"text\"},\"city\":{\"fields\":{\"keyword\":{\"ignore_above\":256,\"type\":\"keyword\"}},\"type\":\"text\"},\"district\":{\"fields\":{\"keyword\":{\"ignore_above\":256,\"type\":\"keyword\"}},\"type\":\"text\"},\"location\":{\"type\":\"geo_point\"},\"province\":{\"fields\":{\"keyword\":{\"ignore_above\":256,\"type\":\"keyword\"}},\"type\":\"text\"}}}";
    public static final String MAPPING_FOR_LOCATION = "{\"properties\":{\"address\":{\"fields\":{\"keyword\":{\"ignore_above\":256,\"type\":\"keyword\"}},\"type\":\"text\"},\"city\":{\"fields\":{\"keyword\":{\"ignore_above\":256,\"type\":\"keyword\"}},\"type\":\"text\"},\"district\":{\"fields\":{\"keyword\":{\"ignore_above\":256,\"type\":\"keyword\"}},\"type\":\"text\"},\"location\":{\"type\":\"geo_point\",\"ignore_malformed\":true},\"province\":{\"fields\":{\"keyword\":{\"ignore_above\":256,\"type\":\"keyword\"}},\"type\":\"text\"}}}";
    /**
     * 地址
     */
    public static final String MAPPING_FOR_ADDRESS = "{\"properties\":{\"address\":{\"fields\":{\"keyword\":{\"ignore_above\":256,\"type\":\"keyword\"}},\"type\":\"text\"},\"city\":{\"fields\":{\"keyword\":{\"ignore_above\":256,\"type\":\"keyword\"}},\"type\":\"text\"},\"district\":{\"fields\":{\"keyword\":{\"ignore_above\":256,\"type\":\"keyword\"}},\"type\":\"text\"},\"province\":{\"fields\":{\"keyword\":{\"ignore_above\":256,\"type\":\"keyword\"}},\"type\":\"text\"}}}";
    /**
     * 指定long类型，预防有的进不去
     */
    public static final String MAPPING_FOR_LONG = "{\"type\":\"long\"}";
    /**
     * 数字默认是double
     */
    public static final String MAPPING_FOR_DOUBLE = "{\"type\":\"double\"}";
    /**
     * date类型（格式化为秒）
     */
    public static final String MAPPING_FOR_DATE_SECOND = "{\"type\":\"date\",\"format\":\"epoch_second\"}";
    /**
     * not_analyzed 不分词
     */
    public static  final String MAPPING_FOR_NOT_ANALYZED = "{\"type\":\"text\",\"fields\":{\"keyword\":{\"type\":\"keyword\",\"index\":\"false\"}}}";
    /**
     * boolean
     */
    public static final String MAPPING_FOR_BOOLEAN = "{\"type\":\"boolean\"}";
}
